package com.ics.cmsadmin.modules.sso.handler;

import com.ics.cmsadmin.frame.core.enums.ApiResultEnum;
import com.ics.cmsadmin.frame.core.exception.CmsException;
import com.ics.cmsadmin.modules.auth.bean.SysUser;
import com.ics.cmsadmin.modules.sso.LoginHandler;
import com.ics.cmsadmin.modules.sso.LoginInfo;
import com.ics.cmsadmin.modules.sso.utils.LoginTypeEnum;
import com.ics.cmsadmin.modules.sso.utils.SsoUtils;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created by 666666 on 2018/8/25.
 */
@Component
public class CmsAdminWebTokenLoginHandler implements LoginHandler<SysUser> {

    @Override
    public SysUser dealWithLogin(HttpServletRequest request, HttpServletResponse response, LoginTypeEnum loginTypeEnum) {
        LoginInfo loginInfo = SsoUtils.getLoginUser(request);
        if (loginInfo == null){
            throw new CmsException(ApiResultEnum.LOGIN_PAST_DUE);
        }
        return (SysUser) loginInfo;
    }
}
